/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nhncorp.neptune.tabletserver;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;

import com.nhncorp.neptune.client.Cell;
import com.nhncorp.neptune.client.CellFilter;
import com.nhncorp.neptune.client.Row;
import com.nhncorp.neptune.common.aop.ProxyObject;
import com.nhncorp.neptune.common.conf.NConfiguration;
import com.nhncorp.neptune.tablet.ColumnValue;
import com.nhncorp.neptune.tablet.TabletInfo;

public interface DiskSSTableIF extends ProxyObject {
  public List<Searchable> getSearchers(Row.Key rowKey, String columnName, Cell.Key columnKey) throws IOException;

//  public void print() throws IOException;

  public void load() throws IOException;

  public ColumnValue findClosestMeta(Row.Key rowKey, String columnName, boolean great) throws IOException;

  public int getMaxMapFileCount();

  public long sumMapFileSize() throws IOException;

  //public Map<String, List<TabletMapFile>> getMapFiles();

  public boolean isEmpty();

  public void majorCompaction() throws IOException;

  public void addTabletMapFile(String columnName, TabletMapFile mapFile) throws IOException;
  
  public void removeTabletMapFile(String columnName, TabletMapFile mapFile) throws IOException;

  public void cancelCompaction(String fileId) throws IOException;

  public Row.Key findMidRowKeyForSplit() throws IOException;

  public DiskSSTableIF[] split(Row.Key midRowaKey, TabletInfo[] splitedTabletInfos) throws IOException;

  public void init(TabletServerIF tabletServer, 
      DiskSSTableIF proxyObject, 
      NConfiguration conf, 
      TabletInfo tabletInfo,
      int numOfVersion);

  public void moveTempToTablet(boolean deleteParent) throws IOException;

  public TabletMapFile mergeMapFiles(String fileId, 
      String columnName, 
      List<TabletMapFile> mergeMapFiles) throws IOException;
  
  public void moveMajorTempToTablet(String columnName, TabletMapFile tabletMapFile) throws IOException;
  
  //public void addMergedMapFile(String columnName, TabletMapFile mergedMapFile) throws IOException;
  
//  public void deleteMergeTargetMapFile(String columnName, List<TabletMapFile> mergeTargetMapFiles) throws IOException;

  public void splitMapFile(Row.Key midRowKey, TabletInfo[] createdTablets, 
                    DiskSSTableIF[] createdDiskSSTables, String columnName, 
                    List<TabletMapFile> columnMapFiles, String fileId) throws IOException;

  public int[] getMapFileCount();

  public int[] getMapFileSize() throws IOException;

  public long getMapFileMemorySize() throws IOException;

  public void truncateColumn(String columnName) throws IOException;
  
  public long[] getMapFileIndexSize() throws IOException;
  
  public Map<String, TabletMapFile> merge(Map<String, 
      List<TabletMapFile>> targetMapFiles, 
      String fileId) throws IOException;
  
  public void moveMergedFile(Map<String, TabletMapFile> mergedMapFiles) throws IOException;
  
  public void addMergedFiles(Map<String, 
      List<TabletMapFile>> targetMapFiles, 
      Map<String, TabletMapFile> mergedMapFiles) throws IOException;

  public boolean hasValue(Row.Key rowKey, String columnName) throws IOException;

  public SortedSet<MapFileIndexRecord> getMapFileIndex();

  public void clearAllMemory();

  public Scanner[] getMapFileScanners(String columnName, Row.Key startRowKey, 
      Row.Key endRowKey, 
      CellFilter cellFilter) throws IOException;
}
